import React from "react";

export const emptyParams = {
  "modelKey": "", // 流程编码
  "modelName": "",  // 流程名称
  "taskName": "",  // 任务名称
  "activityId": "",  // 任务编码
  "status": "",  // 状态
  "startTime": "",  // 开始时间
  "endTime": "",   // 结束时间

};

/*
const buildKeyMap = keys => keys.reduce((map, k) => {
  map[k] = true;
  return map;
}, {});
*/

export function renderStatus(cn, v) {
  let color;
  let label;
  switch (v) {
    case "NORMAL":
      label = "正常";
      color = "#4dcb73";
      break;
    case "WARNING":
      label = "预警";
      color = "#ff9121";
      break;
    case "TIMEOUT":
      label = "超时";
      color = "#ff4948";
      break;
    case "END":
      label = "终止";
      color = "#bfbfbf";
      break;
    case "RECALL":
      label = "撤办";
      color = "#bfbfbf";
      break;
    case "PAUSE":
      label = "暂停";
      color = "#608eff";
      break;
    case "ERROR":
    default:
      label = "错误";
      color = "#d91923";
  }
  return (
    <span>
      <span
        className={cn}
        style={{ backgroundColor: color }}
      />
      <span>{label}</span>
    </span>
  );
}

export function getEllipsisCell(cn, v, maxWidth) {
  return (
    <span
      className={cn}
      style={{
        display: "inline-block",
        maxWidth,
      }}
      title={v}
    >
      {v}
    </span>
  );
}

export function getColumns() {
  const columns = [{
    title: "流程编码",
    dataIndex: "modelKey",
    width:"15%",
  }, {
    title: "流程名称",
    dataIndex: "modelName",
    width:"15%",
  }, {
    title: "任务编码",
    dataIndex: "activityId",
    width:"15%",
  }, {
    title: "任务名称",
    dataIndex: "taskName",
    width:"15%",
  }, {
    title: "任务创建时间",
    dataIndex: "createTime",
    width:160,
  }, {
    title: "状态",
    dataIndex: "status",
    width:120,
    render: this.renderStatus,
  }, {
    title: "任务执行人",
    dataIndex: "operator",
    width:120,
  }];
  return columns;
};
//
// 页码页数改变
export function handlePageChange(pageNum, pageSize) {
  this.setState({ page: { pageNum, pageSize } }, () => {
    this.initData();
  });
};

export function getPageProps(current, pageSize, total) {
  return {
    showQuickJumper: true,
    showSizeChanger: true,
    pageSizeOptions: ["10", "20", "30", "40"],
    current,
    pageSize,
    total,
    onChange: this.handlePageChange,
    onShowSizeChange: this.handlePageChange,
  };
}

// 加载应用数据
export function initAppListData() {
  const { dispatch } = this.props;
  dispatch({ type: "appListMenu/getAppListData" }).then((res) => {
    const { appListMenuData = {} } = res || {};
    if (appListMenuData && appListMenuData.length > 0) {
      // const parameter = this.searchParams
      // this.searchParams.tenantId = `${appListMenuData[0].id}`;
      // parameter.appId = datas.app[0].id
      // this.setState({
      //   selectedKeys: [`${appListMenuData[0].id || "0"}`],
      // });
      this.initData();
    }
  });
}


export function initData() {
  const { dispatch } = this.props;
  const params = this.getQueryParam();
  dispatch({
    type: "Report/getTaskDetail",
    payload: {
      ...params,
    },
  });
}
